import numpy as np
import matplotlib.pyplot as plt
import os
from matplotlib.colors import LogNorm

# define data directory
# data_dir = r'C:\Users\aviram\Dropbox (MIT)\HTG paper\data_repository'
# data_dir = ''
fname = 'exfig2.npz'

# load npz file
# data = np.load(data_dir + '\\' + fname, allow_pickle=True)
data = np.load(fname, allow_pickle=True)
print(data.files)
n = data['n']
B = data['B']
Rxx_sym = data['Rxx_sym']
Rxx_raw = data['Rxx_raw']
Vtg = data['Vtg']
Vbg = data['Vbg']
n0 = data['n0'] # density at charge neutrality point
ns = data['ns'] # density at 4 electron per moire unit cell
device_name = data['device_name']
back_gate_thickness_nm = data['back_gate_thickness_nm']
top_gate_thickness_nm = data['top_gate_thickness_nm']

# plot
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
im = ax.pcolormesh(n, B, Rxx_raw, cmap='inferno',)
ax.set_xlabel('Density ($10^{12}$ cm$^{-2}$)')
ax.set_ylabel('$B$ (T)')
ax.set_title('exfig2')
cbar = fig.colorbar(im, ax=ax)
cbar.set_label('$R_{xx}$ raw (k$\Omega$)')
plt.show()

# plot
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
im = ax.pcolormesh(n, B, Rxx_sym, cmap='inferno', norm=LogNorm(vmin=1e2, vmax=1e4))
ax.set_xlabel('Density ($10^{12}$ cm$^{-2}$)')
ax.set_ylabel('$B$ (T)')
ax.set_title('exfig2')
cbar = fig.colorbar(im, ax=ax)
cbar.set_label('$R_{xx}$ symmetrized (k$\Omega$)')
plt.show()